{extend name='base' /}

{block name='main'}
<div class="main-panel">
    <div class="content">
        <div class="page-inner">
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h4 class="card-title">编辑用户</h4>
                        </div>
                        <div class="card-body">
                            <form id="form">
                                <div class="form-group form-inline">
                                    <label for="group_id" class="col-md-2 col-form-label">所属分组 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <select name="data[group_id]" id="group_id" class="form-control">
                                            <option value="">请选择所属分组</option>
                                            {foreach $group as $k => $v}
                                            <option value="{$v.id}" {if $member['groups'][0]['id'] == $v['id']}selected{/if}>{$v.title}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="title" class="col-md-2 col-form-label">用户名 <span style="color: #f00;">*</span></label>
                                    <div class="col-md-10 p-0">
                                        <input type="text" class="form-control" id="title" name="data[username]" placeholder="请输入用户名" value="{$member.username}">
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="name" class="col-md-2 col-form-label">密码</label>
                                    <div class="col-md-10 p-0">
                                        <input type="password" class="form-control" id="name" name="data[password]" placeholder="请输入密码">
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label for="name" class="col-md-2 col-form-label">重复密码</label>
                                    <div class="col-md-10 p-0">
                                        <input type="password" class="form-control" id="sort" name="data[rpassword]" placeholder="请输入重复密码" value="">
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label class="col-md-2 col-form-label">状态</label>
                                    <div class="col-md-10 p-0" style="display: flex;align-items: center;">
                                        <label class="form-radio-label">
                                            <input class="form-radio-input" type="radio" name="data[status]" value="1" {if $member['status']==1}checked{/if}>
                                            <span class="form-radio-sign" style="margin-top: 0.4rem;margin-left: 0.2rem">启用</span>
                                        </label>
                                        <label class="form-radio-label ml-3">
                                            <input class="form-radio-input" type="radio" name="data[status]" value="0" {if $member['status']==0}checked{/if}>
                                            <span class="form-radio-sign" style="margin-top: 0.4rem;margin-left: 0.2rem">禁用</span>
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group form-inline">
                                    <label class="col-md-2 col-form-label"></label>
                                    <div class="col-md-10 p-0">
                                        <button type="button" class="btn btn-success" onclick="add();">立即提交</button>
                                        <button type="button" class="btn btn-danger" onclick="window.history.back()">返回</button>
                                    </div>
                                </div>
                                <input type="hidden" name="id" value="{$member.id}">
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name='js'}
<script>
    var lock = false;
    function add() {
        if (lock) {
            return false;
        }
        lock = true;
        $.ajax({
            url: "{:url('member/edit')}",
            type: 'post',
            data: $("#form").serialize(),
            dataType: 'json',
            success: function (res) {
                if (res.code == 0) {
                    swal("提示", res.msg, {
                        icon : "error",
                        buttons: {
                            confirm: {
                                className : 'btn btn-danger'
                            }
                        },
                    });
                    lock = false;
                }else{
                    window.history.back();
                }
            }
        })
    }
</script>
{/block}